/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _LINUX_HUGETLB_INLINE_H
#define _LINUX_HUGETLB_INLINE_H

#ifdef CONFIG_HUGETLB_PAGE

#include <linux/mm.h>

static inline bool is_vm_hugetlb_page(struct vm_area_struct *vma)
{
	return !!(vma->vm_flags & VM_HUGETLB);
}

#else

static inline bool is_vm_hugetlb_page(struct vm_area_struct *vma)
{
	return false;
}

#endif

#if defined(CONFIG_RTOS_MEM_HUGEPAGE_SHARED_LIB) && defined(CONFIG_HUGETLB_PAGE)
static inline bool is_vm_so_hugepages(struct vm_area_struct *vma)
{
	return !!(vma->rtos_vm_flags & RTOS_VM_HUGEPAGE_SHARED_LIB);
}

/*
 * If VMA has VM_HUGETLB flag, its size will not be counted in Commited_AS.
 * When VM_HUGETLB flag is removed, its size should be counted.
 */
static inline bool is_vm_hugetlb(struct vm_area_struct *vma,
	unsigned long oldflags, unsigned long newflags)
{
	return (((oldflags & VM_HUGETLB) && !(newflags & (VM_HUGETLB|VM_ACCOUNT)) &&
		(vma->rtos_vm_flags & RTOS_VM_HUGEPAGE_SHARED_LIB)));
}

#else

static inline bool is_vm_so_hugepages(struct vm_area_struct *vma)
{
	return false;
}

static inline bool is_vm_hugetlb(struct vm_area_struct *vma,
	unsigned long oldflags, unsigned long newflags)
{
	return false;
}
#endif /* CONFIG_RTOS_MEM_HUGEPAGE_SHARED_LIB */

#endif
